﻿using System;
using System.Text;

namespace GPS.GPSLanguage
{
    class DGPSToken
    {
        internal static void ParseLanguage(GPSData gpsData, System.Collections.Queue q)
        {
            String timeOfLastUpdate = (string)q.Dequeue();
            double val;
            int seconds = 0;
            int millis = 0;
            try
            {

                if (timeOfLastUpdate.Length > 0)
                {
                    val = double.Parse(timeOfLastUpdate);
                    val *= 1000;
                    seconds = (int)(val / 1000);
                    millis = (int)(val % 1000);
                }
            }
            catch { }



            TimeSpan ts = new TimeSpan(0, 0, 0, seconds, millis);
            gpsData.SetLastDGPSUpdate(ts);

            switch (gpsData.MessageType)
            {
                case MessageType.GPGGA:
                    DGPSStationIDToken.ParseLanguage(gpsData, q);
                    break;
                default:
                    throw new InvalidLanguageException("How did you get here?");
            }
        }
    }
}
